/**
 * 
 */
package com.yidu.erp.action.sell;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yidu.common.Tools;
import com.yidu.erp.model.BeyondMoney;
import com.yidu.erp.model.BeyondPlanmx;
import com.yidu.erp.model.BeyondSalplan;
import com.yidu.erp.model.BeyondStaff;
import com.yidu.erp.model.BeyondWare;
import com.yidu.erp.service.sell.BeyondMoneyService;

/**
 * 财务
 * @author WangGuanfu
 *
 */
@Controller
@RequestMapping("money")
public class BeyondMoneyAction {

	@Resource 
	private BeyondMoneyService beyondMoneyService;
	
	/**
	 * 查询总店销售
	 * @return
	 *//*
	@RequestMapping("selectMoneyByOptime")
	@ResponseBody
	public Map<String, Object> selectMoneyByOptime(){
		Map<String, Object> map = new HashMap<>();
		Map<String, Object> map1 = new HashMap<>();
		
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
		//得到时间日期对象
		Date date = new Date();
		//将时间加入map
		map1.put("optime", sdf.format(new Date()));
		//根据时间查询总店销售
		List<BeyondMoney> money = beyondMoneyService.selectMoneyByOptime(map1);
		//截取出年
		String year = Tools.getDateStr(date).split("-")[0];
		//取出月
		String month = Tools.getDateStr(date).split("-")[1];
		
		map.put("money", money);
		map.put("year", year);
		map.put("month", month);
		return map;
		
	}*/
	/**
	 * 查询分店销售
	 * @return
	 */
	@RequestMapping("selectMoneyByAnnexId")
	@ResponseBody
	public Map<String, Object> selectMoneyByAnnexId(HttpSession session,String test){
		//得到登录的session
		BeyondStaff beyondStaff = (BeyondStaff) session.getAttribute("staff");
		//new一个map
		Map<String, Object> map = new HashMap<>();
		Map<String, Object> map1 = new HashMap<>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
		//得到时间日期对象
		Date date = new Date();
		if(test==null){
			//将时间加入map
			map1.put("optime", sdf.format(new Date()));
			
		}else{
			map1.put("optime", test);
		}
		//将分店ID放到map
		map1.put("annexId", beyondStaff.getAnnexId());
		//根据时间跟分店ID查询分店销售
		List<BeyondMoney> money = beyondMoneyService.selectMoneyByAnnexId(map1);
		//取出年
		String year = Tools.getDateStr(date).split("-")[0];
		//取出月
		String month = Tools.getDateStr(date).split("-")[1];
		map.put("money", money);
		map.put("year", year);
		map.put("month", month);
		return map;
	}
	
	/**
	 * 查询分店商品销量
	 * @return
	 */   
	@RequestMapping("selectWare")
	@ResponseBody
	public Map<String, Object> selectWare(HttpSession session,String test){
		System.out.println("==========================test+++++"+test);
		//得到登录的session
		BeyondStaff beyondStaff = (BeyondStaff) session.getAttribute("staff");
		//new一个map
		Map<String, Object> map = new HashMap<>();
		Map<String, Object> map1 = new HashMap<>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
		//得到时间日期对象
		Date date = new Date();
		if(test==null){
			//将时间加入map
			map1.put("optime", sdf.format(new Date()));
			
		}else{
			map1.put("optime", test);
		}
		
		//将分店ID放到map
		map1.put("annexId", beyondStaff.getAnnexId());
		//根据时间跟分店ID查询分店商品销量
		List<BeyondSalplan> money = beyondMoneyService.selectware(map1);
		//截取出年
		String year = Tools.getDateStr(date).split("-")[0];
		//截取出月
		String month = Tools.getDateStr(date).split("-")[1];
		map.put("money", money);
		map.put("year", year);
		map.put("month", month);
		return map;
	}
	
/*	*//**
	 * 查询总店商品销量
	 * @return
	 *//*
	@RequestMapping("selectZongSale")
	@ResponseBody
	public Map<String, Object>selectZongSale(){
		//new一个map
		Map<String, Object> map = new HashMap<>();
		Map<String, Object> map1 = new HashMap<>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
		//得到时间日期对象
		Date date = new Date();
		//将时间加入map
		map1.put("optime", sdf.format(new Date()));
		//根据时间查询总店销量
		List<BeyondSalplan> money =  beyondMoneyService.selectZongSale(map1);
		//截取出年
		String year = Tools.getDateStr(date).split("-")[0];
		//取出月
		String month = Tools.getDateStr(date).split("-")[1];
		
		map.put("money", money);
		map.put("year", year);
		map.put("month", month);
		return map;
	}*/
	
	/**
	 * 查询会员累计消费金额
	 * @return
	 */
	@RequestMapping("selectMoneyBystaffId")
	@ResponseBody
	public double selectMoneyBystaffId(){
		//new一个map
		Map<String, Object> map = new HashMap<>();
		//查询会员消费金额
		double num =  beyondMoneyService.selectMoneyBystaffId();
		return num;
	}
	
	/**
	 * 查询会员个数
	 * @return
	 */
	@RequestMapping("selectStaffNum")
	@ResponseBody
	public int selectStaffNum(){
	//查询会员个数
	 int count =beyondMoneyService.selectStaffNum();
	 return count;
	}
	
	/**
	 * 查询销售总量
	 * @return
	 */
	@RequestMapping("selectSctockmpNum")
	@ResponseBody
	public int selectSctockmpNum(){
		//查询销售总量
		int sctockmpNum=beyondMoneyService.selectSctockmpNum();
		return sctockmpNum;
	}

	/**
	 * 查询当天的销售量
	 * @return
	 */
	@RequestMapping("selectDate")
	@ResponseBody
	public int  selectDate(){
		//new一个map
		Map<String, Object> map = new HashMap<>();
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM");
		//得到时间日期对象
		Date date = new Date();
		//将时间加入map
		map.put("optime", sdf.format(new Date()));
		//查询销售总量
	    int row= beyondMoneyService.selectDate(map);
		return row;
		
	}
	
	/**
	 * 查询财务总金额
	 * @return
	 */
	@RequestMapping("selectMoneySum")
	@ResponseBody
	public double selectMoneySum(){
		//查询财务总金额
		double sum = beyondMoneyService.selectMoneySum();
		return sum;
	}
}
